//
//  JMHomeApplyView.m
//  NewiOSProject
//
//  Created by JMMac on 25.12.23.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMHomeApplyView.h"
#import "JMProductVC.h"
#import "JMCPIListVC.h"
@interface JMHomeApplyView()
@property (nonatomic, strong)JMHomeModel *model;
@end
@implementation JMHomeApplyView

- (instancetype)initWithFrame:(CGRect)frame model:(JMHomeModel*)model;
{
    self = [super initWithFrame:frame];
    if (self) {
        _model = model;
        self.backgroundColor = Hex_Str_COLOR(@"#F6F9FE");
        
        UIView *contV= [[ UIView alloc]initWithFrame:(CGRectMake(0, 16, kAppW(), frame.size.height-32))];
        contV.backgroundColor =WhiteColor();
        [self addSubview:contV];
        
        UILabel *soloLab = [JMControl createLabelWithFrame:(CGRectMake(0, 24, 150, 24)) Font:fontWithWeight(17, UIFontWeightMedium) Text:@"Pedir préstamo" color:Hex_Str_COLOR(@"#222222")];
        [contV addSubview:soloLab];
        soloLab.backgroundColor = WhiteColor();
        soloLab.textAlignment = 1;
        soloLab.centerX = kAppW()/2;
        
        UIView *lineV = [[UIView alloc]initWithFrame:(CGRectMake(0, 0, 198, 2))];
        lineV.backgroundColor = Hex_Str_COLOR(@"#3C57F8");
        [contV addSubview:lineV];
        [contV sendSubviewToBack:lineV];
        lineV.center = soloLab.center;
        CGFloat w = CalculateLabelWidthWithLab(soloLab)+16;
        soloLab.width = w;
        soloLab.centerX = kAppW()/2;
        lineV.width = w+16+48;
        lineV.centerX = soloLab.centerX;
        
        
        UILabel *topTitleLab = [JMControl createLabelWithFrame:(CGRectMake(24, soloLab.bottom+15, kAppW(), FontH(17))) Font:BoldFont(15) Text:model.unused.stringValue.moneyString color:Text_COLOR_LEVEL1()];
        [contV addSubview:topTitleLab];
      
        
        UILabel *subTitleLab = [JMControl createLabelWithFrame:(CGRectMake(20, topTitleLab.bottom+12, kAppW()-180, 20)) Font:Font(14) Text:@"Importe máximo($)" color:Hex_Str_COLOR(@"#555555")];
        [contV addSubview:subTitleLab];
        
        UIButton *modificarBtn = [JMControl createButtonWithFrame:(CGRectMake(subTitleLab.right+12, subTitleLab.top, 120, 32)) Target:self Action:@selector(modificarBtnClick) Title:@"Solicitar ahora" titlColor:Hex_Str_COLOR(@"#ffffff") font:Font(12) tag:0 backgroundColor:WhiteColor()];
        [contV addSubview:modificarBtn];
        modificarBtn.backgroundColor =   GradientColorWithColor(CGSizeMake(120, 32), FXGradientChangeDirectionHorizontal, mainStartColor(), mainEndColor());
        modificarBtn.cornerRadius = 16;

    }
    return self;
}
-(void)modificarBtnClick
{
    if([self.model.CPIString isEqualToString:@"to_product"]){//to_product查看产品 产品打包页面
        JMProductVC *vc = JMProductVC.new;
        [self.viewController.navigationController pushViewController:vc animated:YES];
    }
    //无产品 无cpi
    if([self.model.CPIString isEqualToString:@"no_product_no_cpi"]){
        
        [JMPublicAlertView showAlertWithFrame:(CGRectMake(0, 0, kAppW()-40, 246)) Title:@"" subTitle:@"Lo sentimos, pero no hay productos disponibles para usted en este momento.." BottomBtns:@[@"ok"] Position:(JMPublicAlertViewPositionCenter) btnDirection:(JMPublicAlertViewButtonDirectionHor)btnActionBlock:^(NSInteger btnTag) {
            
        }];
    }
    
    if([self.model.CPIString isEqualToString:@"to_cpi"]){//无额度的cpi列表
        [JMPublicAlertView showAlertWithFrame:(CGRectMake(0, 0, kAppW()-40, 246)) Title:@"" subTitle:@"Lamentamos que no cumpla con nuestros requisitos de productos de prétamos por el momento, le recomendamos otros productos." BottomBtns:@[@"verificar",@"cancelar "] Position:(JMPublicAlertViewPositionCenter) btnDirection:(JMPublicAlertViewButtonDirectionHor) btnActionBlock:^(NSInteger btnTag) {
            if(btnTag==1){
                JMCPIListVC *vc = [JMCPIListVC new];
                [self.viewController.navigationController pushViewController:vc animated:YES];
            }
        }];
    }
}
@end
